package app;

import java.io.File;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

public class ServerConfig {

	int id;
	String name;
	int port;
	String db;
	int[] connect;
	public int sid;
	
	public static final String loadFile = "config/startConfig/server.xml"; 
	
	public static final String fileSource = "config/startConfig/"; 
	
	@SuppressWarnings("unchecked")
	public ServerConfig(String str) {
		
		 SAXBuilder builder = new SAXBuilder();
		 try {
			Document doc = builder.build(new File(loadFile));
			
			Element element = doc.getRootElement();
			
			Element child = element.getChild(str);
			
			Element obj = child.getChild("id");
			if(obj != null)
			{
				String id = obj.getValue();
				this.id = Integer.parseInt(id);
			}
			obj = child.getChild("name");
			if(obj != null)
			{
				name = obj.getValue();
			}
			obj = child.getChild("port");
			if(obj != null)
			{
				String port = obj.getValue();
				this.port = Integer.parseInt(port);
			}
			obj = child.getChild("db");
			if(obj != null)
			{
				this.db = fileSource + obj.getValue()+".properties";
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		 
	}

	
	
}
